﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Maticsoft.BLL;
using Maticsoft.Model;


namespace FineUI.Examples
{
    public partial class major_top : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Maticsoft.BLL.major majorinfo = new Maticsoft.BLL.major();
                this.DropDownList1.DataSource = majorinfo.selectAllCollName();
                this.DropDownList1.DataTextField = "colleage_name"; //绑定文字对应的字段                
                this.DropDownList1.DataBind();   
                
            }
        }
        public void SelectProductTypeChange(object sender, EventArgs e)
        {
            //TODO:在学院的下拉框选择之后，专业名称的下拉框进行相应更新
            Maticsoft.BLL.major majorinfo = new Maticsoft.BLL.major();
            string colleage_name = this.DropDownList1.SelectedItem.Text.ToString();
            this.DropDownList2.DataSource = majorinfo.selectAllMajName(colleage_name);
            this.DropDownList2.DataTextField = "major_name";//绑定编号对应的字段
            this.DropDownList2.DataBind();
        }
        protected void selectKecheng(object sender, System.EventArgs e)
        {
            Maticsoft.BLL.major majorinfo = new Maticsoft.BLL.major();
            string colleage_name = this.DropDownList1.SelectedItem.Text.ToString();
            string major_name = this.DropDownList2.SelectedItem.Text.ToString();
            //Label1.Text = major_name;

            repKecheng.DataSource = majorinfo.selectAllKechengByCollAndMaj(colleage_name, major_name);
            repKecheng.DataBind();
            //string s_url;
            //s_url = "gridview.aspx?colleage_name=" + Textbox1.Text + "&major_name=" + Textbox2.Text;
            //Response.Redirect(s_url);
            //Response.Write("<script>window.showModalDialog('gridview.aspx')</script>");
            //Textbox1.Text = "";
            //Textbox2.Text = "";
            //SqlConnection con = gridview.createconnection();
            //con.Open();
            //string str = "select * from JH_colleage ";
            //SqlCommand cmd = new SqlCommand(str,con);
            //DataSet ds = new DataSet();
            //SqlDataAdapter adp = new SqlDataAdapter(str, con);
            //adp.Fill(ds, "colleage");
            //Textbox1.Text = ds.Tables["colleage"].Rows[0].ItemArray[1].ToString().Trim();
            //con.Close();
        }
        public void btn_del(Object sender, CommandEventArgs e)
        {
            //Response.Write(e.CommandArgument);
            int keCheng_id = int.Parse((string)e.CommandArgument);
            //Response.Write(keCheng_id);
            Maticsoft.BLL.major majorinfo = new Maticsoft.BLL.major();
            bool aaa = majorinfo.Delete(keCheng_id);
            if (aaa)
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('删除成功，请刷新页面信息！');</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('删除成功，请刷新页面信息！');</script>");
            }
        }

        public void redict(object sender, System.EventArgs e)
        {
            Response.Redirect("~/major_insertKeCheng.aspx");
        }
    }
}